exports.addRedBagActivity = function (req, res) {

    //获取restful参数
    var bodyParams = req.routeInfo.bodyParams;
    //最终结果
    var resultData = {};

    var new_oaid = 0;

    //任务流创建
    async.waterfall([
            //1.权限验证
            /*function (cb) {
                P.permissionValidation(req, res, [CORE_APIConfig.coreAPI.addOrganizationActivity], function () {
                    cb()
                });
            },*/
            //添加活动基本信息
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.addOrganizationActivity,
                        method: 'POST',
                        data: {
                            oa_title: bodyParams.activity_name,
                            oa_type: "6",
                            oa_oid: bodyParams.oid,
                            oa_category_text: bodyParams.category_text == undefined ? "" : bodyParams.category_text,
                            oa_start_time: bodyParams.activity_start_time,
                            oa_end_time: bodyParams.activity_end_time,
                            oa_explain: bodyParams.activity_note == undefined ? "" : bodyParams.activity_note,
                            oa_title_image: bodyParams.activity_image == undefined ? "" : bodyParams.activity_image,
                            oa_title_image_text: bodyParams.oa_title_image_text == undefined ? "" : bodyParams.oa_title_image_text,
                            oa_title_image_text_style: bodyParams.oa_title_image_text_style == undefined ? "" : bodyParams.oa_title_image_text_style,
                            oa_skin_id: bodyParams.oa_skin_id == undefined ? "" : bodyParams.oa_skin_id,
                            oa_music_id: bodyParams.oa_music_id == undefined ? "" : bodyParams.oa_music_id,
                            oa_class_time: bodyParams.oa_class_time == undefined ? "" : bodyParams.oa_class_time,
                            oa_class_duration: bodyParams.oa_class_duration == undefined ? "" : bodyParams.oa_class_duration,
                            oa_class_apply: bodyParams.oa_class_apply == undefined ? "" : bodyParams.oa_class_apply,
                            oa_class_people: bodyParams.oa_class_people == undefined ? "" : bodyParams.oa_class_people,
                            oa_class_basics: bodyParams.oa_class_basics == undefined ? "" : bodyParams.oa_class_basics,
                            oa_class_phone: bodyParams.oa_class_phone == undefined ? "" : bodyParams.oa_class_phone,
                            oa_thumbnail: bodyParams.oa_thumbnail == undefined ? "" : bodyParams.oa_thumbnail,
                            oa_title_image_type: bodyParams.oa_title_image_type == undefined ? "" : bodyParams.oa_title_image_type
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return RES.response(res, false, "活动新增失败，请重新尝试");
                        }

                        new_oaid = data;

                        cb();
                    }
                );

            },

            //增加活动红包

            function (cb) {

                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.addRedBagActivityContent,
                        method: 'POST',
                        data: {
                            rba_type: bodyParams.coupon_type,
                            rba_cid: bodyParams.coupon_id,
                            rba_oaid: new_oaid
                        }
                    },
                    function (err, data) {

                        //console.log(data);

                        //判断是否有错误信息
                        if (err) {
                            resultData.addData = data;
                        }

                        cb();
                    }
                );
            }

        ], function (err, result) {
            //返回最终拼接结果
            RES.response(res, true, resultData);
        }
    );
}